﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学楼课表");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		/* 设置为横向打印 */
		event.setArg("portrait", false);
		
		termId = event.getArg("TID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		buildId = event.getArg("BID");
		
		rs_clsroom = queryNew("cr_id");
		
		if ( len(termId) and len(buildId) ) {
			sql = "	SELECT
						a.cr_id,a.classroom,act.cr_type_name,a.cr_floor,ab.b_name,a.sits_course
					FROM
						t_classroom a INNER JOIN t_classroom_type act ON act.cr_type = a.cr_type
						INNER JOIN t_building ab ON ab.b_id = a.b_id
					WHERE
						EXISTS(
							SELECT 1 FROM t_clsroom_forcourse b INNER JOIN t_clsroom_timetable bct ON bct.crtime_id = b.crtime_id
							WHERE a.cr_id = bct.cr_id
							AND
							a.b_id = :buildId 
							AND
							bct.term_id = :termId 
						)
					ORDER BY
						a.cr_floor,a.classroom";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "buildId", value = buildId, cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			rs_clsroom = queryObj.execute(sql = sql).getResult();
		}
		
	</cfscript>
</cfsilent>

<cfset currentPage = 1 />

<cfloop query="rs_clsroom">

	<!--- 单个教室课表 --->
	<cfset tagCode = "JXCDKB-" & termId & "," & rs_clsroom.cr_id />
    
	<cfset sql = "	SELECT
						cf.tasktime,cf.task_week,cf.task_id,cf.task_type
					FROM
						t_clsroom_forcourse cf INNER JOIN t_clsroom_timetable ct ON ct.crtime_id = cf.crtime_id
						INNER JOIN t_classroom c ON c.cr_id = ct.cr_id
					WHERE
						ct.term_id = :termId 
						AND
						c.cr_id = :clsroomId " />

	<cfset queryObj = new Query(datasource = application.dnsSlave) />
	<cfset queryObj.addParam(name = "clsroomId", value = rs_clsroom.cr_id, cfsqltype = "cf_sql_char") />
	<cfset queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char") />
	<cfset rs_clsroomData = queryObj.execute(sql = sql).getResult() />

	<cfset courseTables = [] />

    <cfloop query="rs_clsroomData">
		
		<!--- /* 载入教学任务 */ --->
        <cfscript>
		
        	switch(rs_clsroomData.task_type){
				
					case 'C':
						sql = "SELECT
							tch.tch_name,
							c.course_name
						FROM
							t_common_task tsk
							INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
							INNER JOIN t_course c ON c.cid = tsk.cid
						WHERE
							 tsk.tsk_id = :taskId ";
						break;
					case 'P':
						sql = "SELECT
							tch.tch_name,
							c.course_name
						FROM
							t_task tsk
							INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
							INNER JOIN t_course c ON c.cid = tsk.cid
						WHERE
							 tsk.tsk_id = :taskId ";
						break;
					case 'R':
						sql = "SELECT
							tch.tch_name,
							c.course_name
						FROM
							t_reopen_task tsk
							INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
							INNER JOIN t_course c ON c.cid = tsk.cid
						WHERE
							 tsk.tsk_id = :taskId ";
						break;
					case 'T':
						sql = "SELECT
							tch.tch_name,
							c.course_name
						FROM
							t_sport_task tsk
							INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
							INNER JOIN t_course c ON c.cid = tsk.cid
						WHERE
							 tsk.tsk_id = :taskId ";
						break;
				}
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name ="taskId", value=rs_clsroomData.task_id, cfsqltype="cf_sql_varchar");
				rs_taskEntity = queryObj.execute(sql = sql).getResult();
        
        </cfscript>
		
		<cfset rowDate = [ rs_taskEntity.course_name, rs_clsroomData.tasktime, '-', rs_clsroomData.task_week, rs_taskEntity.tch_name ] />
		
		<cfset arrayAppend(courseTables, rowDate) />
		
	</cfloop>
	
	<cfif currentPage GT 1><div class="page_break"></div></cfif>
	
	<div class="UIprintableTitle"><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput>学期 <cfoutput>#rs_clsroom.classroom#</cfoutput> 教室课表</div>
	<table width="98%" border="0" cellpadding="1" cellspacing="0">
		<tr>
			<td>位置: <cfoutput>#rs_clsroom.b_name#</cfoutput> <cfoutput>#dictAdvice.getFloorString( rs_clsroom.cr_floor )#</cfoutput></td>
			<td>座位数: <cfoutput>#rs_clsroom.sits_course#</cfoutput></td>
			<td align="right">类别: <cfoutput>#rs_clsroom.cr_type_name#</cfoutput></td>
		</tr>
	</table>
	
	<!-- courseTable -->
	<table class="UIprintable noborder" width="100%" border="1" cellpadding="3" cellspacing="1">
		<thead>
			<tr class="noborder">
				<td colspan="2" width="2%"></td>
				<td width="14%">星期一</td>
				<td width="14%">星期二</td>
				<td width="14%">星期三</td>
				<td width="14%">星期四</td>
				<td width="14%">星期五</td>
				<td width="14%">星期六</td>
				<td width="14%">星期天</td>
			</tr>
		</thead>
		<tbody>
			<cfloop from="1" to="6" index="lec">
				<tr>
					<cfswitch expression="#lec#">
						<cfcase value="1">
							<td rowspan="2" class="noborder"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
						</cfcase>
						<cfcase value="3">
							<td rowspan="2" class="noborder"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
						</cfcase>
						<cfcase value="5">
							<td rowspan="2" class="noborder"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
						</cfcase>
					</cfswitch>
					<td><cfoutput>#mathAdvice.convertLectureIdxToChinese(lec)#</cfoutput></td>
					<cfloop from="1" to="7" index="wkday">
						<td class="timeCell">
							
							<cfloop array="#courseTables#" index="table">

								<cfif table[2] eq wkday & "@" & lec & "-2">
									<div class="lecture">
										<!--- 节次 2 --->
										<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
										<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
										<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
									</div>
								</cfif>

								<cfif table[2] eq wkday & "@" & lec & "-3">
									<div class="lecture">
										<!--- 节次 3 --->
										<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
										<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
										<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(3)</span><br/>
									</div>
								</cfif>

								<cfif (table[2] eq wkday & "@" & lec & "-4") or (table[2] eq wkday & "@" & lec-1 & "-4")>
									<!--- 节次 4 --->
									<div class="lecture">
										<!--- 显示为节次 2 --->
										<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
										<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
										<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
									</div>
								</cfif>
												
								<cfif (table[2] eq wkday & "@" & lec & "-5")>
									<!--- 节次 5 --->
									<div class="lecture">
										<!--- 显示为节次 2 --->
										<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
										<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
										<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
									</div>
									<cfelseif (table[2] eq wkday & "@" & lec-1 & "-5")>
									<div class="lecture">
										<!--- 显示为节次 3 --->
										<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
										<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
										<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(3)</span><br/>
									</div>
								</cfif>
												
								<cfif (table[2] eq wkday & "@" & lec & "-8") or (table[2] eq wkday & "@" & lec-1 & "-8") or (table[2] eq wkday & "@" & lec-2 & "-8") or (table[2] eq wkday & "@" & lec-3 & "-8")>
									<!--- 节次 8 --->
									<div class="lecture">
										<!--- 显示为节次 2 --->
										<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
										<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
										<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
									</div>
								</cfif>
												
							</cfloop>
							
						</td>
					</cfloop>
				</tr>
			</cfloop>
		</tbody>
	</table>
	<!-- /courseTable -->

	<div class="clear2px"></div>
	<table width="100%" cellpadding="0" cellspacing="0">
		<tr>
			<td>打印时间 <cfoutput>#dateFormat(now(), "YYYY年MM月DD日")#</cfoutput></td>
			<td align="right"><img src="<cfoutput>#getContextRoot()#</cfoutput>/barcode/Print/<cfoutput>#tagCode#</cfoutput>.png" height="43"/></td>
		</tr>
	</table>
	
	<cfset currentPage++ />
	

</cfloop>